﻿<?xml version="1.0" encoding="UTF-8"?>
<AppletManifest xmlns="http://openiz.org/mobile/applet">
  <info>
    <name>Patient Search</name>
    <version>1.0.0.0</version>
    <author>OpenIZ.org Community</author>
    <icon>@drawable/patient_search</icon>
    <id>org.openiz.applets.core.patient.search</id>
    <groupName>Patient Management</groupName>
  </info>
  <tile size="sm">
    <text>Search Patients</text>
    <icon>@drawable/patient_search</icon>
  </tile>
  <asset name="index" mimeType="text/html">
    <contentXml>
      <body xmlns="http://www.w3.org/1999/xhtml" ng-controller="PatientSearchController">
        <form name="filterForm">
          <div class="container">
            <div class="row">
              <div class="col-md-12">
                <div class="panel panel-default">
                  <div class="panel-heading">
                    <h2 class="panel-title">
                      <a href="#searchParms" data-toggle="collapse">
                        <span class="glyphicon glyphicon-search">
                        </span> Search Parameters
                      </a>
                    </h2>
                  </div>
                  <div class="panel-collapse in" id="searchParms">
                    <div class="panel-body">
                      <div class="panel panel-default">
                        <div class="panel-heading">
                          <h3 class="panel-title">Barcode Scan</h3>
                        </div>
                        <div class="panel-body">
                          <div class="input-group">
                            <span class="input-group-addon" id="barcodeLabel">Identifier:</span>
                            <input ng-model="searchFilter.barcodeId" type="text" class="form-control" placeholder="0303030303" name="barcodeId" id="barcodeId" aria-describedby="barcodeLabel" />
                            <span class="input-group-addon">
                              <a ng-click="scanBarcode('#barcodeId')">
                                <span class="glyphicon glyphicon-barcode">
                                </span>
                                Scan
                              </a>
                            </span>
                          </div>
                        </div>
                      </div>
                      <div class="panel panel-default">
                        <div class="panel-heading">
                          <h3 class="panel-title">
                            <a role="button" data-toggle="collapse" href="#demoPanel">Patient Demographics Criteria</a>
                          </h3>
                        </div>
                        <div class="panel-collapse collapse" id="demoPanel">
                          <div class="panel-body">
                            <div class="input-group">
                              <span class="input-group-addon" id="firstNameLabel">First Name:</span>
                              <input ng-model="searchFilter.patient.firstName" type="text" class="form-control" placeholder="First/Given Name(s)" name="firstName" id="firstName" aria-describedby="firstNameLabel" />
                            </div>
                            <div class="input-group">
                              <span class="input-group-addon" id="lastNameLabel">Last Name:</span>
                              <input ng-model="searchFilter.patient.lastName" type="text" class="form-control" placeholder="Last/Family Name(s)" name="lastName" id="lastName" aria-describedby="lastNameLabel" />
                            </div>
                            <div class="input-group">
                              <span class="input-group-addon" id="dobDateFromLabel">Date of Birth (from):</span>
                              <input ng-model="searchFilter.patient.dobFrom" type="date" class="form-control" ng-blur="updateDobToMin(searchFilter)" data-max-date="0" name="dobDateFrom" id="dobDateFrom" aria-describedby="dobDateFromLabel" />
                            </div>
                            <div class="input-group">
                              <span class="input-group-addon" id="dobDateToLabel">Date of Birth (to):</span>
                              <input ng-model="searchFilter.patient.dobTo" class="form-control" data-max-date="0" type="date" name="dobDateTo" id="dobDateTo" aria-describedby="dobDateToLabel" />
                            </div>
                            <div class="input-group">
                              <span class="input-group-addon" id="genderLabel">Gender:</span>
                              <select ng-model="searchFilter.patient.gender" class="form-control">
                                <option>---</option>
                                <option value="M">Male</option>
                                <option value="F">Female</option>
                                <option value="UN">Undifferentiated</option>
                              </select>
                            </div>
                          </div>
                        </div>
                      </div>
                      <div class="panel panel-default">
                        <div class="panel-heading">
                          <h3 class="panel-title">
                            <a role="button" data-toggle="collapse" href="#nokPanel">Next of Kin</a>
                          </h3>
                        </div>
                        <div class="panel-collapse collapse" id="nokPanel">
                          <div class="panel-body">
                            <div class="input-group">
                              <span class="input-group-addon" id="relationLabel">Relationship to Client:</span>
                              <select ng-model="searchFilter.nok.relationshipKind" id="relation" class="form-control">
                                <option value="MTH">Mother</option>
                                <option value="FTH">Father</option>
                                <option value="UNC">Aunt/Uncle</option>
                                <option value="SIB">Sibling</option>
                              </select>
                            </div>
                            <div class="input-group">
                              <span class="input-group-addon" id="nokFirstNameLabel">First Name:</span>
                              <input ng-model="searchFilter.nok.firstName" type="text" class="form-control" placeholder="First/Given Name(s)" name="nokFirstName" id="nokFirstName" aria-describedby="nokFirstNameLabel" />
                            </div>
                            <div class="input-group">
                              <span class="input-group-addon" id="nokLastNameLabel">Last Name:</span>
                              <input ng-model="searchFilter.nok.lastName" type="text" class="form-control" placeholder="Last/Family Name(s)" name="nokLastName" id="nokLastName" aria-describedby="nokLastNameLabel" />
                            </div>
                          </div>
                        </div>
                      </div>
                      <div class="panel panel-default">
                        <div class="panel-heading">
                          <h3 class="panel-title">
                            <a role="button" data-toggle="collapse" href="#additionalParms">Additional Search Criteria</a>
                          </h3>
                        </div>
                        <div id="additionalParms" class="panel-collapse collapse">
                          <div class="panel-body">
                            <div class="input-group">
                              <span class="input-group-addon" id="village">City/Village:</span>
                              <input ng-model="searchFilter.patient.city" type="text" class="form-control" placeholder="Village" name="villageId" id="villageId" aria-describedby="villiageLabel" />
                            </div>
                            <div class="input-group">
                              <span class="input-group-addon" id="telephoneLabel">Telephone:</span>
                              <input ng-model="searchFilter.patient.telecom" type="text" class="form-control" placeholder="Telephone Number" name="telephone" id="telephone" aria-describedby="telephoneLabel" />
                            </div>
                          </div>
                        </div>
                      </div>
                      <div class="pull-right btn-group">
                        <button class="btn btn-lg btn-danger" ng-click="close()">
                          <span class="glyphicon glyphicon-remove">
                          </span> Cancel
                        </button>
                        <button class="btn btn-lg btn-primary" ng-click="search(searchFilter)">
                          Search <span class="glyphicon glyphicon-search"></span>
                        </button>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
            <div class="row">
            	<div class="col-md-12">
            		<div class="panel panel-default">
            			<div class="panel-heading">
            				<h2 class="panel-title">
            					<a role="button" href="#searchResults" data-toggle="collapse">Search Results</a>
            				</h2>
            			</div>
            			<table id="searchResults" class="collapse table">
            				<tr>
            					<th>ID</th>
            					<th>Name</th>
            					<th>Gender</th>
            					<th>Date of Birth</th>
            					<th>Village</th>
            					<th></th>
            				</tr>
            				<tr>
            					<td>1029</td>
            					<td>Smith, Jennifer Ashley</td>
            					<td>F</td>
            					<td>2014-MAR-03</td>
            					<td>Village 2</td>
            					<td>
            						<a class="btn btn-primary" href="app://openiz.org/applet/org.openiz.applets.core.patient.checkin/?pid=1029"><span class="glyphicon glyphicon-ok-circle"></span> Check-in</a>
            						<a class="btn btn-default" href="view?pid=1026"><span class="glyphicon glyphicon-circle-arrow-right"></span> View</a>
            					</td>
            				</tr>
            				<tr>
            					<td colspan="5"><a class="btn btn-success" href="app://openiz.org/applet/org.openiz.applets.core.patient.register/"><span class="glyphicon glyphicon-credit-card"></span> Register</a></td>
            				</tr>
            			</table>
            		</div>
            	</div>
            </div>
          </div>
        </form>
        <!-- OpenIZ:Scripts -->
      </body>
    </contentXml>
  </asset>
  <asset name="index-controller" mimeType="text/javascript">
    <contentText>
      <![CDATA[
			// angular stuff
			var searchApp = angular.module('index', []);

			searchApp.controller('PatientSearchController', ['$scope', function ($scope)
			{

				$scope.master = {};

				// scan barcode
				$scope.scanBarcode = function(barcodeTarget)
				{
					$(barcodeTarget).val(OpenIZ.App.scanBarcode());
				}

				// search
				$scope.search = function(filter) {
					//OpenIZ.Patient.search(filter);
					$("#searchParms").collapse(false);
					$("#searchResults").collapse(true);
				};

				//$scope.reset = function() {
				//		$scope.user = angular.copy($scope.master);
				//};

				$scope.close = function() {
					OpenIZ.App.back();
				};

				$scope.updateDobToMin = function(filter)
				{
					$("#dobDateTo").attr("min", OpenIZ.Util.toDateInputString(filter.patient.dobFrom));
				}
				//$scope.reset();
			}]);

		]]>
    </contentText>
  </asset>
  <asset name="view" mimeType="text/html">
  	<contentXml>
      <body xmlns="http://www.w3.org/1999/xhtml" ng-controller="PatientViewController">

	  </body>
  	</contentXml>
  </asset>
  <asset name="view-controller" mimeType="text/javascript">
  	<contentText>
  		<![CDATA[
			var viewApp = angular.module('view', []);

			viewApp.controller('PatientViewController', ['$scope', function ($scope) 
			{
			}]);

  		]]>
  	</contentText>
  </asset>
</AppletManifest>